/** @odoo-module **/
import cellEditor from './cellEditor.js'
import cellRenderer from './cellRenderer.js'
import categoryCellEditor from './categoryCellEditor.js'
import costNumberCellEditor from './costNumberCellEditor.js'
import {dinnerTypeNameComparator,dishNumIdNameComparator} from './comparator.js'
import selectCellEditor from './selectCellEditor.js'



const weekStr = '一二三四五六日';

// 定义列
const col = (owl) => {
    const col = [
        {
            headerName: '类别',
            field: 'dish_top_category_name_cn',
            width: 50,
            editable: false,
            // hide:true,
            // sortable: true,
            menuTabs: [],
            rowSpan: params => {
                return params.context.owl_widget.getRowSpan(params);
            },
            cellClassRules: {
                'row-span':(params)=> params.context.owl_widget.getRowSpan(params) !=1
            }
        },

        {
            headerName: '餐别',
            field: 'dinner_type_category_name',
            width: 80,
            editable: false,
            menuTabs: [],
            sortable: true,
            showRowGroup:true,
            rowGroup: true,
            hide:true,
            comparator: (a,b) => {
                let getData = (v) =>{
                    let data = owl.index.dinner_type_category.find(d=>d.name == v);
                    return data;
                };
                let getNum = (v)=>{
                    let num = v == 'dn2'?2:v=='dn3'?3:v=='dn5'?5:v=='dn1'?1:6;
                    return num;
                };
                let d1 = getData(a);
                let d2 = getData(b);
                let d1Number = getNum(d1.dinner_type);
                let d2Number = getNum(d2.dinner_type);
                if(d1Number == d2Number){
                    d1Number = d1.dt_no;
                    d2Number = d2.dt_no;
                }
                return d1Number - d2Number;
            }
        },
        {
            headerName: '餐别',
            field: 'dinner_type_name',
            width: 80,
            editable: false,
            menuTabs: [],
            // sortable: true,
            // showRowGroup:true,
            // rowGroup: true,
            hide:true,
            // comparator: dinnerTypeNameComparator
        },{
            headerName: 'dish_top_category_id',
            field: 'dish_top_category_id',
            hide:true,
            sortable: true,
            menuTabs: []
        },{
            headerName: '序号/客户',
            field: 'dish_num_id_name',
            width: 70,
            menuTabs: [],
            comparator: dishNumIdNameComparator,
            type: 'editableColumn',
            cellEditor: selectCellEditor,
            cellEditorParams: (params) => {
                let cus_loc = params.context.owl_widget.index.cus_loc.map(v=>{
                    return {
                        id:v.plan_day_cus_name,
                        name:v.plan_day_cus_name
                    }
                })
                return {
                    values:cus_loc
                };
            },
            cellClass:(params)=>{
                if(params.data && params.data.te_pei_json && !params.data.dish_num_id_name){
                    return 'cell-error'
                }

            }
        },
        {
            headerName: 'sequence_tag',
            field: 'sequence_tag',
            width: 80,
            editable: false,
            hide:true,
            sortable: true,
            menuTabs: []
        },
        {
            headerName: 'dish_num_id',
            field: 'dish_num_id',
            width: 80,
            editable: false,
            hide:true,
            sortable: true,
            menuTabs: []
        },
        {
            headerName: 'dinner_type_id',
            field: 'dinner_type_id',
            width: 80,
            editable: false,
            hide:true,
            sortable: true,
            menuTabs: []
        },
        {
            headerName: 'LevelScore',
            field: 'LevelScore',
            width: 80,
            editable: false,
            hide:true,
            sortable: true,
            menuTabs: []
        },

    ];
    // 类别
    for (let i = 1; i < 8; i++) {
        col.push({
            headerName: '周' + weekStr[i - 1],
            field: 'day' + i + '_limit_category_name',
            width: 50,
            menuTabs: [],
            hide:false,
            cellEditor:categoryCellEditor
        });
    }
    //成本
    col.push({
        headerName: '低',
        field: 'minCost',
        width:50,
        menuTabs: [],
        cellEditor: costNumberCellEditor,
    },{
        headerName: '高',
        field: 'maxCost',
        width:50,
        menuTabs: [],
        cellEditor: costNumberCellEditor,
    });
    // 菜品
    for (let i = 1; i < 8; i++) {
        col.push({
            headerName: '周' + weekStr[i - 1],
            field: 'day' + i + '_dish_key_name',
            cellRenderer: cellRenderer,
            flex:1,
            menuTabs: [],
            cellEditor: cellEditor,
            cellClass: params => {},
            minWidth:100,
            type: 'editableColumn',
            valueFormatter:(params)=>{
                let value = params.value;
                if(params.data && params.data.te_pei_json && value){
                    let arr = value.split('/');
                    let str = '';
                    arr.forEach((v,i)=>{
                        if(i == 0){
                            str = v;
                        }else{
                            str += ('/'+owl.formatterTePeiStrToObj(v).name);
                        }
                    })
                    value = str;
                }
                return value;


            }
        });
    }
    return col;
}

export default col;
